<template>
  <div>
    <slot></slot>
  </div>
</template>

<script setup>
import router from "@/router"
import { usePageHeaderStore } from '@/store/modules/pageHeader.js'
import { changeRouteList } from './handel'
import { ElMessage as message } from 'element-plus'

//存在title时，保存上级路由
let props = defineProps({
  title: null
})
const pageHeader = usePageHeaderStore()


//处理上级路由
if (props.title && router.currentRoute._value.matched.length > 1) {
  let arr = changeRouteList(router.currentRoute._value.matched)
  arr[arr.length - 1].name = props.title
  if (typeof arr === 'string') {
    pageHeader.changePageHeader(router.currentRoute._value.matched)
    message.error(arr)
  } else {
    pageHeader.changePageHeader(arr)
  }

} else {
  pageHeader.changePageHeader(router.currentRoute._value.matched)
}

</script>
<style lang="less" scoped>
@import "./index.less";
</style>